package cn.harry.modular.portrait.service.impl;

import cn.harry.modular.portrait.domain.UserSegmentsRelation;
import cn.harry.modular.portrait.mapper.UserSegmentsRelationMapper;
import cn.harry.modular.portrait.service.UserSegmentsRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户分群关联服务实现类
 *
 * @author harry
 * @公众号 Harry技术
 */
@Service
@RequiredArgsConstructor
public class UserSegmentsRelationServiceImpl extends ServiceImpl<UserSegmentsRelationMapper, UserSegmentsRelation> implements UserSegmentsRelationService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveUserSegmentsRelation(List<Long> userIds, Long id) {
        List<UserSegmentsRelation> list = new ArrayList<>();
        for (Long userId : userIds) {
            UserSegmentsRelation item = new UserSegmentsRelation();
            item.setUserId(userId);
            item.setSegmentId(id);
            list.add(item);
        }
        this.saveBatch(list);
    }
}
